ifndef CROSS_COMPILE
CROSS_COMPILE = riscv32-unknown-elf-
endif
CC = riscv32-unknown-elf-gcc
LD = riscv32-unknown-elf-ld
OBJCOPY = riscv32-unknown-elf-objcopy
OBJDUMP = riscv32-unknown-elf-objdump

OBJECTS = inst_rom.o main.o

CFLAG0=-static -nostdlib -nostartfiles -lm -lgcc
CFLAG1=-DPREALLOCATE=1 -mcmodel=medany -static -std=gnu99 -O0 -ffast-math -fno-common -fno-builtin-printf
CFLAG_TEST=-DPREALLOCATE=1 -mcmodel=medlow -static -std=gnu99 -O0 -fno-common -fno-builtin-print


export	CROSS_COMPILE

DEP_SRC=inst_rom.s
TEST_SRC=main.c
# ********************
# Rules of Compilation
# ********************

all: inst_rom.om inst_rom.bin inst_rom.dump inst_rom.data

main.o: main.c
	$(CC) -c $< $(CFLAG0) $(CFLAG1) $(CFLAG_TEST)

inst_rom.o: inst_rom.s
	$(CC) -c $< $(CFLAG0) $(CFLAG1) $(CFLAG_TEST)

inst_rom.om: ram.ld $(OBJECTS)
	$(LD) -T ram.ld $(OBJECTS) -o $@

inst_rom.bin: inst_rom.om
	$(OBJCOPY) -O binary $<  $@
inst_rom.dump: inst_rom.om
	$(OBJDUMP) -D $< > $@
inst_rom.data: inst_rom.bin
	./Bin2Mem -f $< -o $@
clean:
	rm -f *.o *.om *.bin *.data *.mif *.asm
